package com.arqui.admmon_module.client.core.main;

import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.annotations.ContentSlot;
import com.gwtplatform.mvp.client.annotations.ProxyCodeSplit;
import com.gwtplatform.mvp.client.annotations.NameToken;
import com.arqui.admmon_module.client.place.NameTokens;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.gwtplatform.mvp.client.proxy.PlaceRequest;
import com.gwtplatform.mvp.client.proxy.ProxyPlace;
import com.gwtplatform.mvp.client.proxy.RevealContentHandler;
import com.google.inject.Inject;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.GwtEvent.Type;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.gwtplatform.mvp.client.proxy.RevealContentEvent;

public class EventsPresenter extends
		Presenter<EventsPresenter.MyView, EventsPresenter.MyProxy> {
	@ContentSlot 
	public static final Type<RevealContentHandler<?>> SLOT_content = new Type<RevealContentHandler<?>>();

	public interface MyView extends View {
		public Button getLoadB();
		
		public void setLoadB(Button loadB);

		public Button getServicesB();

		public void setServicesB(Button servicesB);

		public Button getInvalidB();

		public void setInvalidB(Button invalidB);
		
		public ScrollPanel getContentPanel();

		public void setContentPanel(ScrollPanel contentPanel);
	}

	@ProxyCodeSplit
	@NameToken(NameTokens.events)
	public interface MyProxy extends ProxyPlace<EventsPresenter> {
	}

	@Inject
	public EventsPresenter(final EventBus eventBus, final MyView view,
			final MyProxy proxy) {
		super(eventBus, view, proxy);
	}

	@Override
	protected void revealInParent() {
		RevealContentEvent.fire(this, HeaderPresenter.SLOT_content, this);
	}
	@Inject
	PlaceManager placeManager;

	@Override
	protected void onBind() {
		super.onBind();
		
		getView().getLoadB().addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				PlaceRequest request = new PlaceRequest(NameTokens.load); 
				placeManager.revealPlace(request);
			}
		});
		
		getView().getServicesB().addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				PlaceRequest request = new PlaceRequest(NameTokens.services); 
				placeManager.revealPlace(request);
			}
		});
		
		getView().getInvalidB().addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				PlaceRequest request = new PlaceRequest(NameTokens.invalid); 
				placeManager.revealPlace(request);
			}
		});
		
	}
	
	
}